# app/main.py

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware


from app.api.internal_endpoints import router as internal_router
from app.core.config import settings
from app.core.logging_config import setup_logging
from app.db.base import Base
from app.db.session import engine

# 创建数据库表
Base.metadata.create_all(bind=engine)

# 初始化日志系统
setup_logging()

app = FastAPI(title=settings.PROJECT_NAME)

# 添加中间件
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],  # 根据需要设置允许的来源
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# 包含所有的路由
app.include_router(internal_router, prefix=settings.API_PREFIX_V1)
